"""
Copyright (c) 2024 [XKW.Beijing]
All rights reserved.

Author: [tangxiaojun]
Email: [417281862@qq.com]
"""
import fasttext

class NlpResource:

    def __init__(self):
        self.model = fasttext.load_model('/Users/tangxiaojun/app/src/python-demo/python/nlp/chinese_new_label_model_20240420.bin')

    def get(self, user_id):
        return {
            "message": f"Hello, World! User ID: {user_id}"
        }

    def predict_model_list(self):
        predictions_text = [
            "游戏行业迎来新一轮监管，加强未成年人保护",
            "奥运会延期举办，运动员备战计划调整",
            "中国一季度GDP上涨5.3%究竟是谁在推动呢？",
            "警方破获一起重大贩毒案件，缴获大量毒品",
            "区块链技术在金融领域应用取得新突破",
            "港股市场迎来反弹，科技股表现抢眼",
            "深圳推出新政策，加强房地产市场调控",
            "政府发布住房保障新措施",
            "股市分析：能源板块迎来投资机会",
            "国产芯片技术取得重大突破",
            "江西国资军工龙头被禁止参与军队采购两年股价一度逼近跌停"
        ]
        result_list = []
        for text in predictions_text:
            # 对文本进行处理，以便于模型预测
            text_split = ' '.join(list(text));
            result_list.append(f"样例 {self.model.predict(text_split)}, {text}")
            # print(f"样例 {self.model.predict(text_split)}, {text}")
        return result_list

    # 预测文本分类，text需要删除标点
    def predict_model_by_text(self, text):
        text_split = ' '.join(list(text));
        return f"样例 {self.model.predict(text_split)}, {text}"
